
//WebSocket
var socket;
if (!window.WebSocket) {
	window.WebSocket = window.MozWebSocket;
}
if (window.WebSocket) {
	socket = new WebSocket("ws://115.231.73.52:7220/");
	socket.onmessage = function(event) {
		console.log("收到服务器消息");
	};
	socket.onopen = function(event) {
		console.log("已连接服务器LQ");
		send(JSON.stringify({"serviceId":1429}));
	};
	socket.onclose = function(event) { // WebSocket 关闭
		console.log("WebSocketLQ已经关闭!");
		socket.close()
	};
	socket.onerror = function(event) {
		console.log("WebSocket异常!");
	};
} else {
	alert("抱歉，您的浏览器不支持WebSocket协议!");
}

// WebSocket发送请求
function send(message) {
	if (!window.WebSocket) { return; }
	if (socket.readyState == WebSocket.OPEN) {
		socket.send(message);
	} else {
		console.log("WebSocket连接没有建立成功!");
		alert("您还未连接上服务器，请刷新页面重试");
	}
}
// function close() {
// 	if (!window.WebSocket) { return; }
// 	if (socket.readyState == WebSocket.OPEN) {
// 		socket.close();
// 	} else {
// 		console.log("WebSocket连接没有建立成功!");
// 		alert("您还未连接上服务器，请刷新页面重试");
// 	}
// }
export { 
 	socket,
}